﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="NewManager.ascx.cs" Inherits="FreshCms.BackEnd.Controls.New.NewManager" %>
<%@ Register Src="~/BackEnd/ControlsCommon/Pager.ascx" TagName="Pager" TagPrefix="uc" %>

<div id="page-content" class="block">
    <div class="block-header">
        <a href="javascript:void(0)" class="header-title-link">
            <h1>Quản lý tin tức</h1>
        </a>
    </div>

    <div class="col-sm-2"></div>
    <div class="col-sm-9">
        <div class="block">
            <div class="block-title"><h2>Chức năng</h2></div>
            <div class="col-sm-12">
                <div class="col-sm-12">
                    <div class="form-group">
                        <div class="input-group">
                            <span class="input-group-addon">Tiêu đề</span>
                            <input type="text" id="txtTitle" class="form-control" value="<%=title %>">
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <div class="input-group">
                            <span class="input-group-addon">Xuất bản ngày</span>
                            <input type="text" id="txtFrom" class="form-control input-datepicker-close text-center" data-date-format="dd/mm/yyyy" placeholder="dd/mm/yyyy" value="<%=from %>">
                            <span class="input-group-addon"><i class="gi gi-calendar"></i></span>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="input-group">
                            <span class="input-group-addon"><i class="fa fa-sitemap"></i></span>
                            <asp:DropDownList ID="ddlCate" runat="server" CssClass="form-control" size="1"></asp:DropDownList>
                            <span class="input-group-addon">Danh mục</span>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <div class="input-group">
                            <span class="input-group-addon">Đến ngày</span>
                            <input type="text" id="txtTo" class="form-control input-datepicker-close text-center" data-date-format="dd/mm/yyyy" placeholder="dd/mm/yyyy" value="<%=to %>">
                            <span class="input-group-addon"><i class="gi gi-calendar"></i></span>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="input-group">
                            <span class="input-group-addon"><i class="gi gi-rotation_lock"></i></span>
                            <asp:DropDownList ID="ddlStatus" runat="server" CssClass="form-control form-control-status" size="1"></asp:DropDownList>
                            <span class="input-group-addon">Trạng thái</span>
                        </div>
                    </div>
                </div>
            </div>

            <div class="form-group text-center">
                <button type="button" id="btnSearch" class="btn btn-sm btn-info"><i class="gi gi-search mr5"></i>Tìm kiếm</button>
                <a href="/BackEnd/?ui=19" id="btnAdd" class="btn btn-sm btn-success"><i class="hi hi-plus mr5"></i>Thêm mới</a>
            </div>
        </div>
    </div>

    <div class="table-responsive">
        <table id="tblParent" class="table table-hover">
            <thead>
                <tr>
                    <th class="text-center" style="width: 60px;">#</th>
                    <th class="text-center" style="width: 60px;">Id</th>
                    <th>Tiêu đề</th>
                    <th>Ngày xuất bản</th>
                    <th style="width: 150px;">Trạng thái</th>
                    <th class="text-center" style="width: 150px;">Thao tác</th>
                </tr>
            </thead>
            <tbody>
                <asp:Repeater ID="rpt" runat="server">
                    <ItemTemplate>
                        <tr id="trMain_<%# Eval("NewId") %>">
                            <td class="text-center"><%# Container.ItemIndex + 1 + ((page-1)*size)%></td>
                            <td class="text-center"><%# Eval("NewId")%></td>
                            <td>
                                <span class="data-title"><%# Eval("NewTitle")%></span>
                                <span class="data-cate">[Danh mục: <b><%# Eval("CatName")%></b>]</span>
                                <span class="data-author">(người tạo: <b><%# Eval("UserMail")%></b>)</span>
                            </td>
                            <td><%# String.Format("{0:dd/MM/yyyy}", Eval("NewPublishDate"))%><span style="font-size: 11px;color: #999;padding-left: 5px;font-style: italic;">(<%# String.Format("{0:hh:mm:ss}", Eval("NewPublishDate"))%>)</span></td>
                            <td><asp:Label ID="lblStatus" runat="server" Text=""></asp:Label></td>
                            <td class="text-center">
                                <div class="btn-group">
                                    <a href="/BackEnd/?ui=19&id=<%# Eval("NewId") %>" data-toggle="tooltip" title="" class="btn btn-xs btn-default"
                                        data-original-title="Xem chi tiết"><i class="gi gi-eye_open"></i></a>
                                    <a href="javascript:void(0)" data-toggle="tooltip" title="" class="btn btn-xs btn-default"
                                        data-original-title="Sửa nhanh" onclick="activeExtTR(<%# Eval("NewId") %>)"><i class="gi gi-pen"></i></a>
                                    <div class="btn-group dropup text-left">
                                        <a href="javascript:void(0)" data-toggle="dropdown" class="btn btn-xs btn-default btn-danger dropdown-toggle"><i class="gi gi-bin"></i> </a>
                                        <ul class="dropdown-menu dropdown-menu-delete">
                                            <li><a href="javascript:void(0)" onclick="DeleteData(<%# Eval("NewId") %>, '<%#Server.HtmlEncode(Eval("NewTitle").ToString())%>')" data-toggle="tooltip" data-original-title="Sản phẩm xóa tạm thời có thể phục hồi tại trang [Lưu Trữ]" data-placement="left">Xóa tạm thời</a></li>
                                            <li><a href="javascript:void(0)">Hủy</a></li>
                                        </ul>
                                    </div>
                                </div>
                            </td>
                        </tr>
                        <tr id="trExt_<%# Eval("NewId") %>" style="display:none/*table-row*/;">
                            <td class="text-center"><%# Container.ItemIndex + 1 %></td>
                            <td class="text-center"><%# Eval("NewId")%></td>
                            <td><input type="text" id="txtTitle_<%# Eval("NewId") %>" class="form-control" value="<%# Eval("NewTitle") %>"></td>
                            <td><%# String.Format("{0:dd/MM/yyyy}", Eval("NewPublishDate"))%><span style="font-size: 11px;color: #999;padding-left: 5px;font-style: italic;">(<%# String.Format("{0:hh:mm:ss}", Eval("NewPublishDate"))%>)</span></td>
                            <td><asp:DropDownList ID="ddlStatus" runat="server" CssClass="form-control form-control-status" rel="status"></asp:DropDownList></td>
                            <td class="text-center">
                                <div class="btn-group">
                                    <a href="javascript:void(0)" data-toggle="tooltip" title="" class="btn btn-xs btn-default btn-success"
                                        data-original-title="Hoàn tất" onclick="UpdateData(<%# Eval("NewId") %>)"><i class="hi hi-ok"></i></a>
                                    <a href="javascript:void(0)" data-toggle="tooltip" title="" class="btn btn-xs btn-default btn-primary" 
                                        data-original-title="Hủy" onclick="activeMainTR(<%# Eval("NewId") %>)"><i class="hi hi-share-alt"></i></a>
                                </div>
                            </td>
                        </tr>
                    </ItemTemplate>
                </asp:Repeater>
            </tbody>
        </table>
    </div>
    <div class="text-center">
        <uc:Pager ID="Pager" runat="server" />
    </div>
</div>

<script>
    $(function () {
        // format color for drop down list
        FormatColorDropList('<%=ddlStatus.ClientID %>');
        // format cho cả list 
        $("#tblParent select[rel*='status']").each(function () {
            FormatColorDropList($(this).attr('id'));
        });
        
    });

    $("#btnSearch").bind("click", function () {
        var link = '/BackEnd/?ui=<%=panelId %>';
        
        if ($('#txtTitle').val().length > 0) link = link + '&title=' + $('#txtTitle').val();
        link = link + '&cate=' + $('#<%=ddlCate.ClientID %>').val();
        if($('#txtFrom').val().length>0) link = link + '&from=' + $('#txtFrom').val();
        if($('#txtTo').val().length>0) link = link + '&to=' + $('#txtTo').val();
        link = link + '&stt=' + $('#<%=ddlStatus.ClientID %>').val();
        
        window.location.href = link;
    });

    // event Update Fast in data table
    function UpdateData(id) {
        var $row = $('#trExt_' + id);
        var title = $('#txtTitle_' + id).val();
        var stt = $row.find('select').val();

        // call ajax
        var param;
        param = {
            m: "updatefast",
            ui : <%=panelId %>,
            id: id,
            title: title,
            stt: stt
        };
        $.ajax({
            url: "/BackEnd/Handler/News.ashx",
            data: param,
            type: "POST",
            dataType: "json",
            beforeSend: function () {
                jWaiting.callWaiting();
            },
            success: function (data) {
                //console.log(data);
                if (data.Success) {
                    jWaiting.callWaitingMessSuccess('Cập nhật tin bài thành công...', 'reload', true);
                }
                else {
                    jWaiting.callWaitingMessError('Có lỗi: ' + data.Message);
                }
            }
        });
    }

    // event Delete Fast in data table
    function DeleteData(id, title) {
        // call ajax
        var param;
        param = {
            m: "recycle",
            ui : <%=panelId %>,
            id: id, 
            title: title
        };
        $.ajax({
            url: "/BackEnd/Handler/News.ashx",
            data: param,
            type: "POST",
            dataType: "json",
            beforeSend: function () {
                jWaiting.callWaiting();
            },
            success: function (data) {
                //console.log(data);
                if (data.Success) {
                    jWaiting.callWaitingMessSuccess('Xóa tạm thời tin bài thành công...', 'reload', true);
                }
                else {
                    jWaiting.callWaitingMessError(data.Message);
                }
            }
        });
    }
</script>